package com.sky.dishflavor.service.impl;

import com.sky.dishflavor.mapper.DishFlavorMapper;
import com.sky.dishflavor.service.DishFlavorService;
import com.sky.entity.DishFlavor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜品口味管理 serviceImpl
 */
@Service
public class DishFlavorServiceImpl implements DishFlavorService {

    @Resource
    private DishFlavorMapper dishFlavorMapper;



    /**
     * 菜品口味
     *        新增单条
     * @param dishFlavor
     */
    @Override
    @Transactional(rollbackFor= Exception.class, propagation= Propagation.REQUIRED) //开启事务
    public Integer insert(DishFlavor dishFlavor) {
        return dishFlavorMapper.insert(dishFlavor);
    }



    /**
     * 菜品口味
     *        新增多条
     * @param flavorList
     */
    @Override
    @Transactional(rollbackFor= Exception.class, propagation= Propagation.REQUIRED) //开启事务
    public Integer insertBatch(List<DishFlavor> flavorList) {
        return dishFlavorMapper.insertBatch(flavorList);
    }



    /**
     * 菜品口味
     *        根据dishIds 删除菜品口味
     * @param dishIds
     */
    @Override
    @Transactional(rollbackFor= Exception.class, propagation= Propagation.REQUIRED) //开启事务
    public Integer deleteByDishIds(List<Long> dishIds) {
        return dishFlavorMapper.deleteByDishIds(dishIds);
    }



    /**
     * 菜品口味
     *        根据菜品id查询口味集合
     * @param dishId
     */
    @Override
    public List<DishFlavor> getByDishId(Long dishId) {
        return dishFlavorMapper.selectByDishId(dishId);
    }


}
